package com.xzp.yygh.common.handler;


import com.xzp.yygh.common.exception.YyghException;
import com.xzp.yygh.common.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result Error(Exception e){
        e.printStackTrace();
        return Result.fail();
    }

    @ExceptionHandler(value = YyghException.class)
    @ResponseBody
    public Result yyghError(YyghException e){
        e.printStackTrace();
        return Result.build(e.getCode(), e.getMessage());
    }
}
